package com.jlh.viewer.acm;

import java.util.Scanner;

/**
 * com.jlh.viewer.acm
 * Created by ASUS on 2017/3/14.
 * 20:28
 */
public class HDU1005 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true){
            int a=sc.nextInt(),b=sc.nextInt(),c=sc.nextInt(),i;
            if (a==0&&b==0&&c==0)
                break;
            int arr[]=new int[105];
            arr[1]=1;
            arr[2]=1;
            for (i=3;i<100;i++){
                arr[i]=(a*arr[i-1]+b*arr[i-2])%7;
                if(arr[i] == 1 && arr[i-1] == 1)
                    break;
            }
            arr[0]=arr[i-2];
            System.out.println(arr[c%(i-2)]);
        }
    }
}
